Add Claude Code smart routing - #255
Open
masonc08 wants to merge 1 commit into
Open
Conversation
masonc08
force-pushed
the
claude-smart-routing
branch
from
July 31, 2026 19:35
504ca15 to
0383b91
Compare
masonc08
force-pushed
the
codex-intelligent-routing
branch
from
July 31, 2026 20:24
a6207dd to
579a5cb
Compare
masonc08
force-pushed
the
claude-smart-routing
branch
2 times, most recently
from
July 31, 2026 21:01
bce872b to
f1b5ad9
Compare
Extend smart routing to Claude Code on top of the shared engine. `ucode claude --enable-smart-routing` routes the root session (via ANTHROPIC_MODEL) and subagents (via a PreToolUse hook that rewrites the Agent tool's model) through the workspace task_v1 router. - smart_routing/claude_routing.py + claude_hooks.py: Claude cc-scenario arms (claude-opus-4-8, claude-sonnet-5, harness "claude"), both offered unconditionally per the frozen task_v1 menu; settings.json hook shape. - claude agent + CLI: --enable/--disable-smart-routing, hidden claude-router-hook, reads the shared smart_routing_enabled state key so one opt-in covers codex and claude. Co-authored-by: Isaac
masonc08
force-pushed
the
codex-intelligent-routing
branch
from
July 31, 2026 21:18
f29d4d0 to
db235b4
Compare
masonc08
force-pushed
the
claude-smart-routing
branch
from
July 31, 2026 21:18
f1b5ad9 to
659c0f1
Compare
rohita5l
marked this pull request as ready for review
July 31, 2026 22:12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
Extends smart routing to Claude Code, on top of the shared smart-routing engine introduced in the base PR #251.
ucode claude --enable-smart-routingopts a workspace into AI Gateway model routing for Claude Code:task_v1router picks betweenclaude-opus-4-8andclaude-sonnet-5; the pick is pinned viaANTHROPIC_MODEL.PreToolUsehook (matcherAgent|Task) rewrites the spawned subagent'smodelviahookSpecificOutput.updatedInput;SessionStart/SubagentStarthooks drive a canary + audit trail.--disable-smart-routingsurgically removes only ucode's own hooks and clears artifacts.The two Claude arms are offered to the router unconditionally, matching the frozen
task_v1cc-scenario menu (which rejects an under-offered request); if an arm isn't servable it fails open to the family default. Reads the sharedsmart_routing_enabledstate key, so one opt-in covers both Codex and Claude Code.Stacking
Stacked on #251 (base branch
codex-intelligent-routing), which carries the shared engine + rename. This PR only adds Claude-specific files and wiring; it touches no Codex routing logic. Review #251 first — once it merges this will be rebased ontomain.How do you know it works?
test_claude_routing.py: thecc-menu request shape, the missing-arm short-circuit, router-pick → workspace-id resolution, fail-open on router error, the subagentmodelrewrite (AgentandTasktool names), and the decision→SubagentStart audit reconciliation.test_agent_claude.py: enable/disable, hook installation intoucode-settings.json, theANTHROPIC_MODELroot pin, and provider-mode suppression of routing hooks.test_e2e_user_agentfailure needs a live gateway and fails identically on the base branch.Not yet validated with a live/liteswap Claude Code session, and routing only activates once the
task_v1router servesharness: "claude"in the target workspace.This pull request and its description were written by Isaac.